package com.itheima.dao;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Map;

public interface OrderSettingListDao {
    @Select("<script>Select m.name,phoneNumber,o.orderDate,orderType,orderStatus,( SELECT NAME FROM t_setmeal WHERE id = setmeal_id ),o.id from t_member m,t_order o,t_setmeal s where m.id = o.member_id and o.setmeal_id = s.id" +"<if test=\"queryString!=null and queryString!=''\">and(m.phoneNumber=#{queryString} or m.name=#{queryString} or m.id=#{queryString})</if>"
            +"<if test=\"startDate!=null and endDate!=null and startDate!='' and endDate!=''\">and (o.orderDate between #{startDate} and #{endDate})</if>" +
            "<if test=\"orderType!=null and orderType!=''\">and o.orderType=#{orderType}</if>" +
            "<if test=\"orderStatus!=null and orderStatus !=''\">and o.orderStatus=#{orderStatus}</if>" +
            "order by orderDate ASC</script>")
    Page<Map> selectByCondition(@Param("queryString")String queryString,
                                @Param("startDate") String startDate,
                                @Param("endDate") String endDate,
                                @Param("orderType") String orderType,
                                @Param("orderStatus") String orderStatus);

    @Update("UPDATE t_order SET orderStatus= #{status} WHERE id = #{id}")
    void setStatus(@Param("status") String status,@Param("id") Integer id);
}
